// 2.1联盟操作
;(function(){
	var bus_a = require("./1. 注册商家").bus_a;
	var BusCon = require("../bus/_con");
	var AdminCon = require("../admin/_con");
	var LeagueCon = require("../league/_con");

	var bus_b = new BusCon({
		name:"农家乐",
		address:"China.ShangHai",
		password:"123456"
	});
	var admin_a = new AdminCon({
		name:"myadmin",
		password:"123456"
	});

	var league_id = admin_a.createLeague("LOL",{
		intro:"hehe",
		avalon:bus_a._id
	});
	var league = LeagueCon.get(league_id);

	console.log("获取盟主");
	var avalon = league.getRole(bus_a._id);
	console.log(avalon,avalon.league_role);

	console.log("添加管理员",bus_a.info.name);
	try{
		avalon.addAdmin(bus_a._id);
	}catch(e){
		console.log(e)
	}
	console.log("添加成员",bus_b.info.name);
	avalon.addMerchants([bus_b._id]);
	console.log("获取商家成员列表：",league.getBuses());

	console.log("设置管理员",bus_b._id);
	avalon.setAdmin(bus_b._id)
	console.log("获取商家成员列表：",league.getBuses());

	if (false) {
		console.log("移除管理员",bus_b._id);
		avalon.removeAdmin(bus_b._id);
		console.log("获取商家成员列表：",league.getBuses());

		console.log("移除成员",bus_b.info.name);
		avalon.removeMerchants([bus_b._id]);
		console.log("获取商家成员列表：",league.getBuses());
	}else{
		console.log("解散联盟");
		avalon._dismissLeague();
		console.log(bus_b.league);
	}


}());